<?php

namespace App\Imports;


use Maatwebsite\Excel\Concerns\WithMultipleSheets;
use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\ToCollection;
use PhpOffice\PhpSpreadsheet\Shared\Date;
use stdClass;
use App\Models\DeptModel;
use App\Models\AdminRoleModel;

class SalaryImport implements ToCollection, WithMultipleSheets
{


    private $result;

    public function __construct() {
        $this->result = new stdClass;
    }

    public function collection(Collection $rows){
        $lines = [];
        $this->result->error = [];

//        'staff_name' => $item->staff ? $item->staff->name : '',
//                'staff_name_en' => $item->staff ? $item->staff->staff_name_en : '',
//                'staff_role' => $item->staff->role ? $item->staff->role->name : '',
//                'job_level' => $item->staff ? $item->staff->job_level : '',
//                'employment_start_date' => $item->staff ? $item->staff->employment_start_date : '',
//                'resignation_date' => $item->staff ? $item->staff->resignation_date : '',
//                'monthly_base_salary' => $item->staff ? $item->staff->monthly_base_salary : '',
//                'work_days' => $item->work_days,
//                'actual_work_days' => $item->actual_work_days,
//                'rest_over_days' => $item->rest_over_days,
//                'holiday_over_days' => $item->holiday_over_days,
//                'company_yl' => $item->company_yl,
//                'company_yil' => $item->company_yil,
//                'company_sy' => $item->company_sy,
//                'company_gs' => $item->company_gs,
//                'company_syu' => $item->company_syu,
//                'company_gjj' => $item->company_gjj,
//                'company_sbgjj_add' => $item->company_sbgjj_add,
//                'company_sbgjj_back' => $item->company_sbgjj_back,
//                'company_total' => $item->company_total,
//                'salary_base' => $item->salary_base,
//                'salary_gwjt' => $item->salary_gwjt,
//                'salary_jbgz' => $item->salary_jbgz,
//                'salary_cb' => $item->salary_cb,
//                'salary_txbz' => $item->salary_txbz,
//                'salary_qqj' => $item->salary_qqj,
//                'salary_bmf' => $item->salary_bmf,
//                'salary_jj' => $item->salary_jj,
//                'salary_bt' => $item->salary_bt,
//                'salary_total' => $item->salary_total,
//                'staff_yl' => $item->staff_yl,
//                'staff_yil' => $item->staff_yil,
//                'staff_sy' => $item->staff_sy,
//                'staff_gjj' => $item->staff_gjj,
//                'staff_tax' => $item->staff_tax,
//                'staff_other' => $item->staff_other,
//                'staff_sbgjj_add' => $item->staff_sbgjj_add,
//                'staff_sbgjj_back' => $item->staff_sbgjj_back,
//                'staff_total' => $item->staff_total,
//                'salary' => $item->salary,
//                'remarks' => $item->remarks


        foreach ($rows as $k => $row) {
            if($k < 1) continue;

            if($row[0] == '' || $row[0] == '合计') continue;

            $lines[] = [
                'staff_name' => $row[0],
                'staff_name_en' => $row[1],
                'staff_role' => $row[2],
                'job_level' => $row[3],
                'employment_start_date' => $row[4],
                'resignation_date' => $row[5],
                'monthly_base_salary' => $row[6],
                'work_days' => $row[7],
                'actual_work_days' => $row[8],
                'rest_over_days' => $row[9],
                'holiday_over_days' => $row[10],
                'company_yl' => $row[11],
                'company_yil' => $row[12],
                'company_sy' => $row[13],
                'company_gs' => $row[14],
                'company_syu' => $row[15],
                'company_gjj' => $row[16],
                'company_sbgjj_add' => $row[17],
                'company_sbgjj_back' => $row[18],
                'company_total' => $row[19],
                'salary_base' => $row[20],
                'salary_gwjt' => $row[21],
                'salary_jbgz' => $row[22],
                'salary_cb' => $row[23],
                'salary_txbz' => $row[24],
                'salary_qqj' => $row[25],
                'salary_bmf' => $row[26],
                'salary_jj' => $row[27],
                'salary_bt' => $row[28],
                'salary_total' => $row[29],
                'staff_yl' => $row[30],
                'staff_yil' => $row[31],
                'staff_sy' => $row[32],
                'staff_gjj' => $row[33],
                'staff_tax' => $row[34],
                'staff_other' => $row[35],
                'staff_sbgjj_add' => $row[36],
                'staff_sbgjj_back' => $row[37],
                'staff_total' => $row[38],
                'salary' => $row[39],
                'remarks' => $row[40],
            ];
        }

        $this->result->lines = $lines;
    }

    public function sheets(): array {
        return [ 0 => $this];
    }

    public function get_result(){
        return $this->result;
    }


}
